// 引入基础请求地址
import {baseurl} from "@/config/baseUrl.js"
// 注意区分requst和request
// console.log((uni.getStorageSync('baseurl') || this.$baseurl))
function requst(url, data, post_get) {
	 // 解决api请求头改变是，第一次调用还是旧的带数据方式
	 // console.log((uni.getStorageSync('baseurl') || this.$baseurl), baseurl)
	var zhnewheader = {
		'sysDataBaseName':"DB_TDW1_SC",
		'content-type': 'application/json',
		'accessToken': uni.getStorageSync("token") || '' ,
		'databaseName': uni.getStorageSync("databaseName") || '' , // uni.getStorageSync("databaseName")
		'organizationNo': uni.getStorageSync("organizationNo") || '', //
		'organizationList': uni.getStorageSync("organizationList") || '', //
		'virtualSystemNo': uni.getStorageSync("virtualSystemNo") || '' //
	}
	// 组织结构idlist设置
	let neworglist = uni.getStorageSync("organizationList") 
	if(neworglist){
		let neworgstr = ""
		neworglist.forEach((neworgitem,neworgindex) => {
			neworgstr = neworgstr + neworgitem
			if(neworgindex < neworglist.length - 1){
				neworgstr += ","
			}else{
				zhnewheader.organizationList = neworgstr
			}
		}
		
		)
	}
	return new Promise((resolve, reject) => {
		uni.request({
			url: (uni.getStorageSync('baseurl') || baseurl) + url,
			method: post_get || "GET",
			data: data || {},
			header: zhnewheader,
			success: (res) => {
				resolve(res)
			},
			fail: (res) => {
				uni.showToast({
					title:"网络请求错误啦",
					icon:'none'
				})
				reject(res)
			}
		})
	})
}
 
module.exports = {
	requst: requst
}